package com.alfred.springboot.elasticjob.lite.demo;

import com.alfred.springboot.elasticjob.lite.common.context.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

@Slf4j
@SpringBootApplication
public class MyApplication {

    public static void main(String[] args) {
        try {
            SpringApplication.run(MyApplication.class, args);
            formatPrint();
        } catch (Exception ex) {
            //catch启动异常信息，方便排除问题
            ex.printStackTrace();
            log.error("**** MyApplication启动失败", ex);
        }
    }

    private static void formatPrint() {
        String profile = SpringContextHolder.getActiveProfile();
        Environment env = SpringContextHolder.getBean(Environment.class);
        log.info(
                "\n    ~~~~ env.port    - {} ~~~~" +
                        "\n    ~~~~ env.profile - {} ~~~~" +
                        "\n    ~~~~ env.name - stageloan-marketing ~~~~", env.getProperty("server.port"), profile);
    }

}
